#include<bits/stdc++.h>
using namespace std;
const int N = 8005,INF = 0x3f3f3f3f;
int a[N],n;
int dp[2][305][305],now = 1,lst;
int main()
{
    freopen("build.in","r",stdin);
    freopen("build.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    for(int i = 1;i <= n;i++) cin>>a[i];
    memset(dp[now],0x3f,sizeof(dp[now]));
    dp[now][0][0] = 0;
    for(int i = 1;i <= n;i++)
    {
        swap(now,lst);
        memset(dp[now],0x3f,sizeof(dp[now]));
        for(int j = 0;j <= i;j++)
        {
            int lp = j,rp = n-i+j+1;//要么对上lp，要么对上rp
            for(int k = 0;k <= i;k++)
            {
                int lv = k,rv = n-i+k+1;
                dp[now][j][k] = min(dp[now][j][k],dp[lst][j][k] + (rv != a[rp]));
                if(j) dp[now][j][k] = min(dp[now][j][k],dp[lst][j-1][k] + (rv != a[lp]));
                if(j && k) dp[now][j][k] = min(dp[now][j][k],dp[lst][j-1][k-1] + (lv != a[lp]));
                if(k) dp[now][j][k] = min(dp[now][j][k],dp[lst][j][k-1] + (lv != a[rp]));
                //if(i == 1 && j == 0 && k == 0)
                //{
                //    cout<<i<<" "<<j<<" "<<k<<" "<<dp[now][j][k]<<" "<<a[lp]<<" "<<a[rp]<<" "<<lv<<" "<<rv<<"\n";
                //}
                //if(dp[now][j][k] != INF) cout<<i<<" "<<j<<" "<<k<<" "<<dp[now][j][k]<<" "<<a[lp]<<" "<<a[rp]<<" "<<lv<<" "<<rv<<"\n";
            }
        }
    }
    int ans = INF;
    for(int i = 0;i <= n;i++)
    {
        for(int j = 0;j <= n;j++)
        {
            ans = min(ans,dp[now][i][j]);
        }
    }
    cout<<ans<<"\n";
    return 0;
}